package com.github.thinwonton.springboot.showcase.jta.config;

import com.alibaba.druid.pool.DruidDataSource;

public class DruidDataSourceBuilder {
    public static <DS extends DruidDataSource> void config(DS druidDataSource, DruidDataSourceProperties properties) {
        druidDataSource.setUrl(properties.getUrl());
        druidDataSource.setUsername(properties.getUsername());
        druidDataSource.setPassword(properties.getPassword());
        druidDataSource.setDriverClassName(properties.getDriverClassName());
//        druidDataSource.setInitialSize(properties.getInitialSize());
//        druidDataSource.setMaxActive(properties.getMaxActive());
//        druidDataSource.setMinIdle(properties.getMinIdle());
//        druidDataSource.setMaxWait(properties.getMaxWait());
//        druidDataSource.setTimeBetweenEvictionRunsMillis(properties
//                .getTimeBetweenEvictionRunsMillis());
//        druidDataSource.setMinEvictableIdleTimeMillis(properties
//                .getMinEvictableIdleTimeMillis());
//        druidDataSource.setValidationQuery(properties.getValidationQuery());
//        druidDataSource.setTestWhileIdle(properties.isTestWhileIdle());
//        druidDataSource.setTestOnBorrow(properties.isTestOnBorrow());
//        druidDataSource.setTestOnReturn(properties.isTestOnReturn());
//        druidDataSource.setPoolPreparedStatements(properties
//                .isPoolPreparedStatements());
//        druidDataSource.setMaxPoolPreparedStatementPerConnectionSize(properties
//                .getMaxPoolPreparedStatementPerConnectionSize());
//
//        try {
//            if (null != druidDataSource) {
//                druidDataSource.setFilters("wall,stat");
//                druidDataSource.setUseGlobalDataSourceStat(true);
//                druidDataSource.init();
//            }
//        } catch (Exception e) {
//            throw new RuntimeException(
//                    "load datasource error, dbProperties is :", e);
//        }
    }
}
